<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE-edge,chrome=1"/><!--用IE的最高版本浏览网页，以防低版本IE不支持部分css3属性-->
		<title>工程界-欢迎登陆</title>
		<meta name="viewport" content="width=device-width,initial-scale=1"/><!--意思是使网页的宽度强制适应不同服务窗口的宽度（宽度自适），且用户不能够随意缩放网页-->
		<meta name="description" content=""/><!--关键字的描述内容(description)-->
		<meta name="keywords" content=""><!--关键字(keywords)-->
		<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" />
		<link rel="icon" href="img/favicon.ico" type="image/x-icon" />
		<link rel="stylesheet" type="text/css" href="css/reset.css" />
		<link rel="stylesheet" type="text/css" href="css/main.css" />
		<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>	
		<!--<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.0/jquery.min.js"></script>-->
		<script type="text/javascript" src="js/reg.js"></script>
		<script type="text/javascript" src="js/url.js"></script>
		<script type="text/javascript" src="js/cookie.js"></script>
		<script type="text/javascript" src="js/globalVariable.js"></script>
</head>
	<body>
		<div class="header">
			<div class="container">
				<h1 class="logo fl"><a href=""><img src="img/logo.png" alt="" title=""/></a></h1>
			</div>			
		</div>
		<div class="contenr container">
			<div class="container clearfix">
				<div class="login fr">
					<div class="login-header clearfix">
						<span class="log">欢迎登录</span>							
						<a href="reg.html" target="_blank" class="fr">点击注册</a>
					</div>
					<div class="login-msg">
						<form action="" method="" name="">
							<div class="itme item-form1">
								<label for="" class="log-box log-label"></label>
								<input type="text" name="username" id="login_user" class=" itxt username" autocomplete="off" placeholder="用户名/手机号/邮箱"/>
								<span class="clear-box clear-btn"></span>
							</div>
							<div class="form-tip">
								
							</div>
							<div class="itme item-form2">
								<label for="" class=" log-box log-labe2"></label>
								<input type="password" name="password" id="login_password" class="itxt password" autocomplete="off" placeholder="密码"/>
								<span class="clear-box clear-btn2"></span>
							</div>
							<div class="form-tip">
							</div>
							<div class="item-form3">
								<div class="safe clearfix">
									<span>
										<input type="checkbox" checked="checked" id="save" />
										<label for="">下次自动登录</label>
									</span>
									<span class="pw-safe fr"><a href="forget-password.html" target="_blank" >忘记密码</a></span>
								</div>
							</div>
							<div class="form-tip">
								<span class="user_password"></span>
							</div>
							<div class="item-form4">
								<div class="login-btn">
									<a href="javascript:;">登录</a>
								</div>
							</div>
						</form>
					</div>	
				</div>
			</div>	
		</div>
	</body>
<script  type="text/javascript">
//登陆密码验证
window.onload=function(){
	 
	 
//	 alert(getAuth().seed)
//	 alert(getAuth().authToken);
		        
   function setCookie(name,value,oDays) {
        var date = new Date()
        date.setDate(date.getDate() + oDays)
        document.cookie = name + "=" + escape(value) +
            ((oDays == null) ? "" : ";expires=" + date.toGMTString())
    }
//  setCookie('username',111);
//  setCookie('password',111);

//   function getCookie(name) {
//      if (document.cookie.length > 0) {
//          c_start = document.cookie.indexOf(name + "=")
//          if (c_start != -1) {
//              c_start = c_start + name.length + 1
//              c_end = document.cookie.indexOf(";", c_start)
//              if (c_end == -1) c_end = document.cookie.length
//              return unescape(document.cookie.substring(c_start, c_end))
//          }
//      }
//      return ""
//  }

    //删除Cookie
//  function removeCookie(name,path){  
//      var name=escape(name);  
//      var expires=new Date(0);  
//      path=path== "" ? "" : ";path="+path;  
//      document.cookie=name+"="+";expires="+expires.toUTCString()+path;  
//  }  

//	var a=getCookie('username');
//	var b=getCookie('password');
	
	var loginType=0;
//	var timeStampConce="";	
//	function getTimeStampConce() {
//		var timestamp = Math.round(new Date().getTime()/reg.code);
//		len = 4;
//		var chars='ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz';	
//		var maxPos=chars.length;
//		var pwd ="";
//		for(i=0; i<len; i++) {
//			pwd+=chars.charAt(Math.floor(Math.random()*maxPos));
//		}
//		return timestamp+pwd;
//	}
//	var timeStampConceTmp = getTimeStampConce();
//		timeStampConce=timeStampConceTmp;
	var getToken=getCookie("authToken");
	
	$(".login-btn a").on({
		'click':function(){
			
			var username=$("#login_user").val();
	        var password=$("#login_password").val();
	        var log=$("input#save").attr("checked");
	        var regex_phone =/^1[3|4|5|7|8]\d{9}$/;
	        var regex_email =/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	        //var log=$("input#save").is(":checked");
	        if(username == '' &&  password == ''){
	            $(".itme").css("border","1px solid red");        	
	          	$(".user_password").css({"color":"red","fontSize":"14px"});
	            $(".user_password").html("您输入的账号或密码有误! 请重新输入"); 
	        }else{
	        	alert("成功");	        	
	        	if(regex_phone.test(username)){
	        		loginType=1;	        		
	        	}else if(regex_email.test(username)){
	        		loginType=2;
	        	}
	        	
	        $.ajax({ 
		        type:"POST",
		        dataType:"json",
		        //url:'http://192.168.0.16:8080/eLink/api/checkVerifyCode?username='+username+'&password='+password+'&.jsessionid='
		        //url:$url+'/api/login/'+0,
		        url:"http://192.168.0.12:8080/elink_user/user/login/"+loginType,
		        contentType:'application/json;charset=UTF-8',
		        data:
		        	JSON.stringify({
		        		loginName:$("#login_user").val(),
		        		passwd:$("#login_password").val()		        	
		        	})			        	
		        ,				      
		        success: function(result) {	
		        	//alert(result.data.authToken);
		        	//setCookie("authToken",result.data.authToken);
		        	//setAuthToken(result.data.authToken);
		        	//alert(getCookie('authToken'))
		             if (result.code == reg.code) {
		             	//setAuth(result.data.seed,result.data.authToken);
		             	alert("注册成功");
		             	setAuth(result.data.seed,result.data.authToken)
		             	
		             	alert(result.data.seed);
		             	alert(result.data.authToken);
		             	
		             	
		             	
		             	if(result.data.authToken!=null){
		             		alert("身份无效");
		             		//setAuthToken(result.data.authToken);
		             	}else{
		             		alert("身份有效");
		             	}		             	
		             	if($("#save").attr("checked")){
							alert("我选中了");
			            	alert("7");
			                setCookie('username',username,7);
			                setCookie('password',password,7);
			            }else{
			            	alert("我没有被选中了");
			            	alert("1")
			                setCookie('username',username,1);
			                setCookie('password',password,1);
			            }
			            
			            if(getCookie("username")){
			            	alert("为什么了");
							$(".reg-su em").html(getCookie("username"))
						}
			            document.location ="reg3.html";
			            
		            	$("#phone").css("border","1px solid #ddd");
	 					$("span#phone_error").css("color","#ddd");				           
		            } else {
		            	alert("登陆失败");
		            	$(".itme").css("border","1px solid red");        	
	          			$(".user_password").css({"color":"red","fontSize":"14px"});
	            		$(".user_password").html("您输入的账号或密码有误! 请重新输入"); 
		            } 
		            
		           
		        },
		         error:function(jqXHR){     
		           alert("发生错误：" + jqXHR.status)  
		        }  
    		});	
	        	
	        	
//	        	$.ajax({ 
//				        type:"GET",
//				        dataType:"json",
//				        url:$url+'/user/checkPhone/?username='+username+"&password="+password+"",
//				        beforeSend: function () {
//				        	$(".msg-phone-icon").css("display","none");
//						},
//				        success: function(result) {
//				        	//alert("11")
//				        	//alert(result.rtnCode);
//				            if (result.rtnCode == reg.code) {
//				            	//alert("2");
//				            	$("#phone").css("border","1px solid #ddd");
//			 					$("span#phone_error").css("color","#ddd");
//								$(".phone-tip i").removeClass("user-error-errors"); 
//								$(".msg-phone-icon").css("display","block");
//								
//				                //alert(result.rtnMessage);
//				            } else  {
//				                $("#phone").css("border","1px solid red");
//			 					$("span#phone_error").css("color","red");			 					
//								$(".phone-tip i").addClass("user-error-error");
//								$("span#phone_error").html("手机号已经被占用，请重新注册");								
//				            } 
//				        },
//				         error:function(jqXHR){     
//				           alert("发生错误：" + jqXHR.status)  
//				        }  
//		    		});
		    		
//	        	if(log != undefined){
				
	            
	        }
		}
	})	
//	$(".login-btn a").bind({
//		'click':function(){
//			var username=$("#login_user").val();
//	        var password=$("#login_password").val();
//	        var log=$("input#save").attr("checked");   
//	       $.ajax({
//	       	type:"post",
//	       	url:"hep.php",
//	       	dataType:'json',
//	       	data: 'username='+username+'&password='+password, //发给php的数据有两项，分别是上面传来的u和p 
//			beforeSend: function () {
//				$("#loading").css("display", "block"); //点击登录后显示loading，隐藏输入框
//				$("#login").css("display", "none");
//			},
//	       	success: function(data){//如果调用php成功  
//				//alert(json.username+'n'+data.password); //把php中的返回值（data.username）给 alert出来  
//				//$('#result').html("姓名:" + data.username + "<br/>密码:" + data.password); //把php中的返回值显示在预定义的result定位符位置  
//				if(username==data.username && password==data.password){
//		            if(log != undefined){
//		            	alert("7");
//		                setCookie('username',username,7);
//		                setCookie('password',password,7);
//		            }else{
//		            	alert("1")
//		                setCookie('username',username,1);
//		                setCookie('password',password,1);
//		            }
//		            document.location ="reg3.html";
//					$(".aa").html(getCookie("username"));
//		        }else{
//		        	$(".itme").css("border","1px solid red");        	
//		          	$(".user_password").css({"color":"red","fontSize":"14px"});
//		            $(".user_password").html("您输入的账号或密码有误! 请重新输入"); 
//		        }
//	       	},
//	       	async:true
//	       });
}
</script>
</html>
